<template>
  <section style="text-align: left">
    <el-dialog
      :title="title"
      :visible.sync="dialogFormVisible"
      @close="clear">
      <el-form :model="categoryForm" ref="CategoryForm">
        <el-form-item label="名称" :label-width="formLabelWidth" prop="name">
          <el-input v-model="categoryForm.name"/>
        </el-form-item>
        <el-form-item label="描述" :label-width="formLabelWidth" prop="nameZh">
          <el-input type="textarea" v-model="categoryForm.description"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="onsubmit">确 定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>
export default {
  name: "CategoryAdd_Update",
  data() {
    return {
      title: '',
      dialogFormVisible: false,
      categoryForm: {
        name: '',
        description: ''
      },
      formLabelWidth: '120px',
    }
  },
  methods: {
    clear() {
      this.categoryForm = {
        name: '',
        description: ''
      }
    },
    add() {
      this.dialogFormVisible = true
      this.title = '服务添加'
    },
    edit(row) {
      this.dialogFormVisible = true
      this.categoryForm = Object.assign({},row)
      this.$emit('reload')
    },
    onsubmit() {
      let data = Object.assign({}, this.categoryForm)

      this.$axios.post('/category/add_update', data).then(resp => {
        if (resp && resp.status === 200) {
          if (resp.data.code === 200) {
            this.$message({
              message: resp.data.result,
              type: "success"
            })
          }
          if (resp.data.code === 400) {
            this.$message({
              message: resp.data.result,
              type: "warning"
            })
          }
          this.clear()
          this.dialogFormVisible = false
          this.$emit('reload')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
